package baiqitun.stupro.common.entity;

import baiqitun.stupro.common.constant.SysConstant;
import baiqitun.stupro.common.validate.group.*;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 与数据库表对应的所有实体类公共字段的抽象
 * @author kedaji
 */
@ApiModel("实体基类")
@Data
@Accessors(chain = true)
public class Entity implements Serializable{

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL,groups = {SaveRootGroup.class, SaveGroup.class})
    @NotBlank(message = "id不能为空", groups = {UpdateGroup.class})
    @ApiModelProperty("主键id")
    @TableId(value = "id", type = IdType.INPUT)
    private String id;

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty(" 排序id，按时间生成的有序id")
    @TableField(value = "sort_id", fill = FieldFill.INSERT)
    private Long sortId;

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty(" 逻辑删除(0-正常,1-已删除)")
    @TableLogic
    @TableField(value = "deleted")
    private String deleted;


    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty("创建人用户名")
    @TableField(value = "create_by")
    private String createBy;

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty("创建时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_datetime", fill = FieldFill.INSERT)
    private LocalDateTime createDateTime;

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty("修改人用户名")
    @TableField("update_by")
    private String updateBy;

    @Null(message = SysConstant.ER_PARAMETER_MUST_NULL, groups = {SaveRootGroup.class, SaveGroup.class, UpdateGroup.class})
    @ApiModelProperty("更新时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_datetime", fill = FieldFill.UPDATE)
    private LocalDateTime updateDateTime;
}

